package com.getpebble.android.jskit;

import com.getpebble.android.common.core.trace.Trace;
import java.util.Arrays;
import java.util.UUID;

public class JsApplicationInfo {
    private String[] capabilities;
    private String computedAppInfoDigest = "";
    private QuerySet computedCapabilitiesSet;
    private UUID constructedUuid;
    private String longName;
    private String shortName;
    private String uuid;
    private int versionCode;
    private String versionLabel;

    protected static class QuerySet {
        public String[] property_set;

        public String[] getPropertySet() {
            try {
                return (String[]) Arrays.copyOf(this.property_set, this.property_set.length);
            } catch (Exception e) {
                Trace.error("JsApplicationInfo", "unable to copy properties", e);
                return new String[0];
            }
        }

        protected QuerySet(String[] property_set) {
            try {
                this.property_set = (String[]) Arrays.copyOf(property_set, property_set.length);
            } catch (Exception e) {
                this.property_set = null;
                Trace.error("JsApplicationInfo", "unable to copy properties", e);
            }
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            if (this.property_set != null) {
                for (String s : this.property_set) {
                    if (s != null) {
                        sb.append(" " + s);
                    }
                }
            }
            sb.append(sb.length() > 1 ? " ]" : "]");
            return sb.toString();
        }
    }

    public void setAppInfoDigest(String digest) {
        if (digest == null) {
            digest = "";
        }
        this.computedAppInfoDigest = digest;
    }

    protected JsApplicationInfo(JsApplicationInfo c) {
        this.longName = c.longName;
        this.shortName = c.shortName;
        this.uuid = c.uuid;
        try {
            this.constructedUuid = UUID.fromString(c.uuid);
        } catch (Exception e) {
            this.constructedUuid = null;
            this.uuid = null;
            Trace.error("JsApplicationInfo", "unable to decode UUID", e);
        }
        this.versionCode = c.versionCode;
        this.versionLabel = c.versionLabel;
        if (c.capabilities != null) {
            this.capabilities = (String[]) Arrays.copyOf(c.capabilities, c.capabilities.length);
            this.computedAppInfoDigest = c.computedAppInfoDigest;
        }
    }

    public String getShortName() {
        return this.shortName;
    }

    public String getLongName() {
        return this.longName;
    }

    public String getUuidString() {
        return this.uuid;
    }

    public UUID getUuid() {
        if (this.constructedUuid == null) {
            try {
                this.constructedUuid = UUID.fromString(this.uuid);
            } catch (Exception e) {
            }
        }
        return this.constructedUuid;
    }

    public int getVersionCode() {
        return this.versionCode;
    }

    public String appInfoDigest() {
        return this.computedAppInfoDigest;
    }

    private synchronized void computeCapabilitySet() {
        if (this.computedCapabilitiesSet == null) {
            if (this.capabilities == null) {
                this.computedCapabilitiesSet = new QuerySet();
            } else {
                this.computedCapabilitiesSet = new QuerySet(this.capabilities);
            }
        }
    }

    public String[] getCapabilities() {
        computeCapabilitySet();
        return this.computedCapabilitiesSet.getPropertySet();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("JsApplicationInfo");
        sb.append("{app long name ='").append(this.longName).append('\'');
        sb.append(", app short name ='").append(this.shortName).append('\'');
        sb.append(", uuid ='").append(this.uuid).append('\'');
        sb.append(", version code =").append(this.versionCode);
        sb.append(", ui version string='").append(this.versionLabel).append('\'');
        if (this.capabilities != null) {
            computeCapabilitySet();
            sb.append(", app capability keys='").append(this.computedCapabilitiesSet.toString()).append('\'');
        }
        sb.append(", appinfo digest fingerprint=").append(this.computedAppInfoDigest);
        sb.append('}');
        return sb.toString();
    }
}
